package org.myspringframework.aop.aspectj;

import org.myspringframework.aop.MethodBeforeAdvice;

import java.lang.reflect.Method;

public class AspectJMethodBeforeAdvice implements MethodBeforeAdvice {
    //通知方法
    protected Method aspectJAdviceMethod;
    //切面class类
    private Class<?> aspectClass;

    public AspectJMethodBeforeAdvice(Method aspectJAdviceMethod,Class<?> aspectClass) {
        this.aspectJAdviceMethod = aspectJAdviceMethod;
        this.aspectClass=aspectClass;
    }

    @Override
    public void before(Method method, Object[] args, Object target) throws Throwable {
        //todo:不new而是在spring容器中获取
        aspectJAdviceMethod.invoke(aspectClass.newInstance(),args);
    }
}
